package com.boot.unity.api.modules.training.service.impl;

import com.boot.unity.api.common.Result;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.boot.unity.api.modules.training.service.RegionService;
import com.boot.unity.api.modules.training.dao.RegionDao;
import com.boot.unity.api.modules.training.entity.Region;
/**
 * @author anonymous
 *
 * @create 2020-06-06 22:06:43
 */
@Service
@AllArgsConstructor
public class RegionServiceImpl implements RegionService {
    private final RegionDao regionDao;

    @Override
    public Result save(Region region) {
        String inscode = region.getInscode();
        String seq = region.getSeq();
        Region r = regionDao.getByInscodeAndSeq(inscode,seq);
        int num;
        if (r == null){
            num = regionDao.save(region);
        }else {
            num = regionDao.updateByInscodeAndSeq(region);
        }
        if (num > 0){
            return Result.success();
        }
        return Result.fail();
    }

    @Override
    public Result deleteByInscodeAndSeq(String inscode, String seq) {
        int num = regionDao.deleteByInscodeAndSeq(inscode,seq);
        if (num > 0){
            return Result.success();
        }
        return Result.fail();
    }
}
